
var xmlcities;

	function fillRegions(http_request) {
		var xmlDocument = http_request.responseXML;

//        $(region).style.display="";
        document.getElementById("region").style.display="";
/*
alert(
http_request.responseText
);
*/
		//put returned XML in the textarea
//		$('result').value = http_request.responseText;
		var xmlregions = xmlDocument.getElementsByTagName('region');

        $(region).options.length = 0;
        for(i=0; xmlregions[i]; i++ ) {
//            $(region).options[i] = new Option(
        document.getElementById("region").options[i] = new Option(
                xmlregions[i].attributes.getNamedItem("name").value,
                xmlregions[i].attributes.getNamedItem("fips_region").value
            );
        }
   }
   
    function fillCities(http_request) {
		var xmlDocument = http_request.responseXML;

        //$(city).style.display="";

/*
alert(
http_request.responseText
);
*/
		//put returned XML in the textarea
//		$('result').value = http_request.responseText;
		
		
/*		
		var xmlcities = xmlDocument.getElementsByTagName('city');

        $(city).options.length = 0;
        for(i=0; xmlcities[i]; i++ ) {
            $(city).options[i] = new Option(
                xmlcities[i].attributes.getNamedItem("accentcity").value,
                xmlcities[i].attributes.getNamedItem("id").value
            );
        }
        */
        
        $(cityfield).style.display="";
        $(citylist).style.display="";
        
        xmlcities = xmlDocument.getElementsByTagName('city');

        var resultArray = new Array();
        for(i=0; xmlcities[i]; i++ ) {
            resultArray[i] = xmlcities[i].attributes.getNamedItem("accentcity").value;
        }
        
        new Autocompleter.Local('cityfield', 'citylist', resultArray, {});
   }
   
   function getcitycode()
   {
        var citydesc = $(cityfield).value;
        
        for(i=0; xmlcities[i]; i++)
        {
            if (xmlcities[i].attributes.getNamedItem("accentcity").value == citydesc)
            {
                $(citycode).value = xmlcities[i].attributes.getNamedItem("id").value;
                return;
            }
        }
         
   }
   
   function updateRegions() {

        alert("updateRegions()");

		var url = 'http://fricchettone/ajax/util.aspx';
		var pars = "&command=GIMMEREGIONS" 
					+ "&country=" + $F('country') ;

//        top.freak.location.href=url;

		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: fillRegions
			});
   }

   function updateCities() {

        alert(  $F('region')  );

		var url = '/ajax/util.aspx';
		var pars = "&command=GIMMECITIES" 
					+ "&country=" + $F('country') 
					+ "&region=" + $F('region') ;
		alert(url+pars);
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: fillCities
			});
   }
